Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not read position when tar archive stream is unseekable #70178

Merged
merged 6 commits into from
Jun 3, 2022

Conversation

carlossanlop
Copy link
Member

Fixes: #70172

The position was being read at the very last moment of creating the archive, to set the archive size one byte after the empty records. This causes an exception to be thrown when compressing directly into a gzip stream, which is unseekable (position cannot be accessed).

cc @rainersigwald

@ghost
Copy link

ghost commented Jun 2, 2022

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes: #70172

The position was being read at the very last moment of creating the archive, to set the archive size one byte after the empty records. This causes an exception to be thrown when compressing directly into a gzip stream, which is unseekable (position cannot be accessed).

cc @rainersigwald

Author: carlossanlop
Assignees: carlossanlop
Labels:

area-System.IO

Milestone: -

Assert.Equal(TarEntryType.RegularFile, entry.EntryType);
Assert.Null(reader.GetNextEntry());
}

[Fact]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a test that verifies the behavior of the TarEntry.DataStream when reading an unseekable stream:

public void GetNextEntry_CopyDataFalse_UnseekableArchive_Exceptions()

But that test wasn't creating an archive using TarWriter against an unseekable stream, hence why this bug wasn't caught before. That's why I'm also adding this extra test to write to a generic unseekable stream.

public class CompressedTar_Tests : TarTestsBase
{
[Fact]
public void TarGz_TarWriter_TarReader()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these tests related to the fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This test passes a GZipStream (an unseekable stream) to the TarWriter. TarWriter will finish adding the entries, then will add the two empty records, and then it would've called that incorrect SetLength call (which I just removed completely since it's not needed).

@carlossanlop carlossanlop merged commit 1d6f23a into dotnet:main Jun 3, 2022
@carlossanlop carlossanlop deleted the UnseekableBug branch June 3, 2022 07:06
@ghost ghost locked as resolved and limited conversation to collaborators Jul 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a tar directly into a GZipStream crashes when writing final records
4 participants